/* 后缀表达式计算器 */

%{
#define YYSTYPE double
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int yylex (void);
void yyerror (char const *);
%}

%token T_NUM
%token T_ADD T_SUB T_MUL T_DIV T_NEG T_POW
%token EOL

%% /* Grammar rules and actions follow. */

input:
	input line
    | /* empty */ {printf("empty\n");}
	;

line: EOL   {printf("newline\n");}
	| exp EOL { printf ("\t%.10g\n", $1); }
	;

exp: T_NUM { $$ = $1; }
	| exp exp T_ADD { $$ = $1 + $2; }
	| exp exp T_SUB { $$ = $1 - $2; }
	| exp exp T_MUL { $$ = $1 * $2; }
	| exp exp T_DIV { $$ = $1 / $2; }
	| exp exp T_POW { $$ = pow ($1, $2); }
	| exp T_NEG { $$ = -$1; }
	;
%%

int main (void)
{
	return yyparse();
}


void yyerror (char const *s)
{
	fprintf (stderr, "%s\n", s);
}